package com.nofx.mydemo.listener;

import com.nofx.mydemo.event.CustomSpringEvent;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * 自定义SpringEvent监听器
 * @author yyc-01407250
 * @date 2021年05月11日 14:00
 */
@Slf4j
@Component
public class CustomSpringEventListener implements ApplicationListener<CustomSpringEvent> {

    @Async
    @Override
    @SneakyThrows
    public void onApplicationEvent(CustomSpringEvent event) {
        TimeUnit.SECONDS.sleep(2);
        log.info("Received spring custom event -" + event.getMessage());
    }
}
